package algorithm.poj.p1000;

import java.io.BufferedReader;
import java.io.InputStreamReader;


public class P1015TLE {

	public static void main(String[] args)
	throws Exception {

		BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));

        String line;
        int c = 0;
        String[] ps;
        String s = "";

        line = stdin.readLine().trim();
        while (!"0 0".equals(line)) {
        	c ++;
        	ps = line.split("\\s+");
        	int n = Integer.valueOf(ps[0]);
        	int m = Integer.valueOf(ps[1]);
        	
        	int[][] dp = new int[n][];
        	for (int i = 0; i < n; i ++) {
                line = stdin.readLine().trim();
                ps = line.split("\\s+");
                int d = Integer.valueOf(ps[0]);
                int p = Integer.valueOf(ps[1]);
        		dp[i] = new int[] {d, p};
        	}
            s += "Jury #" + c + "\n" + jury(m, dp) + "\n";
            line = stdin.readLine().trim();
        }
		
		System.out.println(s);
		
//		Result a = jury(2, new int[][] {
//				new int[] {1, 2},
//				new int[] {2, 3},
//				new int[] {4, 1},
//				new int[] {6, 2}
//		});
//		System.out.println(a);
	}
	
	public static class Result {
		int D;
		int P;
		int[] R;
		
		public Result(int d, int p, int[] r) {
			this.D = d;
			this.P = p;
			this.R = r;
		}
		
		@Override
		public String toString() {
			String str = "Best jury has value " + this.P + " for prosecution and value " + this.D + " for defence:\n";
			for (int i = 0; i < this.R.length; i ++) {
				str += " " + (this.R[i]+1);
			}
			return str;
		}
	}
	
	private static Result jury(int m, int[][] dp) {
		
		int[] c = new int[m];
		for (int i = 0; i < m; i ++) {
			c[i] = i;
		}
		int MIN = Integer.MAX_VALUE;
		int D = 0;
		int P = 0;
		int[] R = null;
		while (c != null) {
			int d = 0;
			int p = 0;
			for (int i = 0; i < m; i ++) {
				p += dp[c[i]][0];
				d += dp[c[i]][1];
			}
			int min = Math.abs(d-p);
			if (min < MIN || (min == MIN && d+p>D+P)) {
				D = d;
				P = p;
				MIN = min;
				R = new int[m];
				System.arraycopy(c, 0, R, 0, m);
			}
			c = next(dp.length, c);
		}
		return new Result(D, P, R);
	}

	public static int[] next(int n, int[] c) {
		
		int r = c.length;
		int j = -1;
		for (j = r-1; j > -1; j --) {
			if (c[j]<(n-r)+j) {
				break;
			}
		}
		if (j == -1) {
			return null;
		} else {
			int[] newC = new int[r];
			for (int i = 0; i < j; i ++) {
				newC[i] = c[i]; 
			}
			for (int i = j; i < r; i ++) {
				newC[i] = c[j] + (i-j+1);
			}
			return newC;
		}
	}
}
